package com.wms.service.impl;

import com.wms.dto.InspectDto;
import com.wms.entity.ArrivalQualityInspection;
import com.wms.mapper.ArrivalQualityInspectionMapper;
import com.wms.service.ArrivalQualityInspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArrivalQualityInspectionServiceImpl implements ArrivalQualityInspectionService {
    @Autowired
    ArrivalQualityInspectionMapper arrivalQualityInspectionMapper;

    @Override
    public List<ArrivalQualityInspection> queryInspectById(int arrivalId) {
        return arrivalQualityInspectionMapper.selectInspectById(arrivalId);
    }

    @Override
    public int updateInspectById(InspectDto inspectDto) {
        //采购数量
        int num=inspectDto.getNum();
        //不合格数
        int notQualifiedNum=inspectDto.getNotQualifiedNum();
        //合格数
        int qualifiedNum=(num-notQualifiedNum);
        inspectDto.setQualifiedNum(qualifiedNum);
        //合格率
        double yield=num > 0 ? ((double)qualifiedNum / num):0;
        inspectDto.setYield(yield);
        return arrivalQualityInspectionMapper.updateInspectById(inspectDto);
    }

}
